using System;
namespace armcontrolgui
{
	[System.ComponentModel.ToolboxItem(true)]
	public partial class AxisView : Gtk.Bin
	{
		private bool bo_DisableEvent;
		private Axis CurrentAxis;
		
		public AxisView (Axis MyAxis)
		{
			this.Build ();
			
			this.CurrentAxis = MyAxis;
			
			this.CurrentAxis.PositionUpdated +=  HandleCurrentAxisPositionUpdated;
			
			this.AxisNameLabel.Text = this.CurrentAxis.Name;
			
			this.AxisScale.Adjustment.Lower = this.CurrentAxis.Minimum;
			this.AxisScale.Adjustment.Upper = this.CurrentAxis.Maximum;
			this.AxisScale.Value = this.CurrentAxis.Position;
		}

		private void HandleCurrentAxisPositionUpdated (Axis Sender)
		{
			RunGtkThread.RunOnGtkThread(()=>{
				if(this.bo_DisableEvent || Sender != this.CurrentAxis)
					return;
				
				this.bo_DisableEvent = true;
				this.AxisScale.Value = this.CurrentAxis.Position;
				this.bo_DisableEvent = false;
			});
		}
		protected virtual void ScaleValueChangedEvent (object sender, System.EventArgs e)
		{
			if(this.bo_DisableEvent || this.CurrentAxis.Position == this.AxisScale.Value)
				return;
			
			this.bo_DisableEvent = true;
			this.CurrentAxis.Position = this.AxisScale.Value;
			this.bo_DisableEvent = false;
		}
		
	}
}

